/*自定义 easyUI 设置*/
/*重写datagrid组件相关组件默认属性*/
(function ($) {
    //分页组件
    var pageDef = $.fn.pagination.defaults
    $.fn.pagination.defaults=$.extend({},pageDef,{
        pageSize:10,
        pageNumber:1,
        pageList:[10,20,50,100],
        //showPageList:false,
        showRefresh:false,
        //        showPageInfo:false,
        beforePageText:'第',
        afterPageText:'/{pages}页',
        displayMsg:'从 {from} 到 {to} ,共 {total} 记录',
    })
    //datagrid组件
    var def = $.fn.datagrid.defaults
    $.fn.datagrid.defaults=$.extend({},def,{
        //fitColumns:true,
        width:'auto',
        height:560,
        border:false,
        fitColumns:true,
        toolbar: '#dgTool',
        striped:true,
        method:'get',
        idField:'id',
        loadMsg:'加载中,请稍后...',
        pagination:true,
        rownumbers:true,
        singleSelect:true,
        pagePosition:'bottom',
        pageNumber:1,
        pageSize:10,
        pageList:[10,20,50,100],
        rownumberWidth:30,
        //loader:function(){},
        loadFilter:function(res){
            if(res.success){
                var data = $.extend({},res.result,{rows:res.result.records,records:null})
                return data
            }else{
                $.messager.alert('错误消息',res.message,'error',null)
            }
        }
    })

})(jQuery);

$(function(){
    // 重写列表
    var ops = $('.dg-list').datagrid('options');
    var url = $.rootUrl+$('.dg-list').attr('uri');
    var newOps = $.extend({},ops,{
        url:url,
        onBeforeLoad:function(param){
            var param2 = $('.query-form').serializeArray();
            $.each(param2,function(i,item){
                if(item.value){
                    param[item.name]=item.value
                }
            })
        },
        onLoad:function(){

        },
        onLoadSuccess:function(data){

        },
        onLoadError:function(){
        }
    })

    $('.dg-list').datagrid(newOps);




    // 查询按钮绑定
    $('#query-btn').linkbutton({
        iconCls:'icon-search',
        onClick:function(){
            $('.dg-list').datagrid('reload');
        }
    })

});

$(function(){

    // 默认dialog hide
    $("#mockDialog").dialog('close')

    // 查询按钮绑定
    $('#query-btn').linkbutton({
        iconCls:'icon-search',
        onClick:function(){
            $('.dg-list').datagrid('reload');
        }
    })

});


function dataTxtFormat(value,row,index){
    return value ? '<a href=javascript:showJsonOrXml('+index+')>点击查看</a>' : null;
}

function showJsonOrXml(index){
    var rows = $('#info-table').datagrid('getRows');
    var row = rows[index]
    var dataTxt = row['dataTxt']
    $("#mockDialog").dialog({
        title:'数据文本',
        resizable: true,
        cache: false,
        modal: true,
        maximizable: false,
        maximized:true,
        minimizable: false
    })
    $("#mockDialog").dialog('open')
    $('#dataTxtBox').textbox('setValue',dataTxt)

}


/*加载数据提示*/
function ajaxLoading() {
    $("<div class=\"datagrid-mask\"><iframe id=\"iframe1\" src=\"about:blank\" frameBorder=\"0\" marginHeight=\"0\" marginWidth=\"0\" style=\"position:absolute; visibility:inherit; top:0px;left:0px;width:100%; height:100%;z-index:-1; filter:alpha(opacity=0.5);\"></iframe></div>").css({ "display": "block", "z-index": "999999" }).appendTo("body");
    $("<div class=\"datagrid-mask-msg\" style='z-index: 999999'></div>").html("正在处理中,请稍候。。。").appendTo("body").css({ "display": "block", "left": ($(document.body).outerWidth(true) - 190) / 2, "top": ($(window).height() - 200) / 2 });
}
/*去掉加载数据提示*/
function ajaxLoadEnd() {
    $(".datagrid-mask").remove();
    $(".datagrid-mask-msg").remove();
}

